<?php
/**
 * FileName: BaseAdminController.php
 * Author: Fei.Song
 * Date: 2021/4/1 11:34
 * Created by PhpStorm
 * Desc: 后台管理基类
 */

namespace App\Http\Controllers;

use App\Service\LogService;
use Illuminate\Http\Request;

class BaseAdminController extends Controller {
    use TraitController,TraitValidation;

    public function __construct(Request $request) {
        $this->middleware(function ($request, $next) {
            $this->guard_name = "admin";
            $this->request = $request;
            $this->_init();

            return $next($request);
        });
    }

    //处理返回路由标识
    public function reRoute($flag) {
        $result = [];
        //处理结果
        switch ($flag) {
            case 0:
                $result = $this->error(70000, "路由不存在不可以添加");
                break;
            case 1:
                $result = $this->success("", "路由可以添加");
                break;
            case 2:
                $result = $this->error(70000, "路由不存在不可以添加");
                break;
        }
        return $result;
    }

    //开启日志
    public function log($level, $module, $action, $message, $data = null) {
        (new LogService())->log($level, $module, $action, $message, $data);
    }

}
